package com.wisdom.springbootdemo;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 11951
 * Date: 2025-03-01
 * Time: 20:32
 */
@RequestMapping("/Demo")
@Controller
@ResponseBody
public class DemoController {
    //    1.返回静态页面
//        2.返回数据@ResponseBody
    @RequestMapping("/D1")
    public Object Demo(){
        return "/demo.html";
    }
    @RequestMapping("/D2")
    public String returnData(){
        return "ResponseBody返回数据";
    }
//    3.返回HTML代码⽚段
    @RequestMapping("/D3")
    public String HTML(){
        return "<h1>hello,springMVC~~</h1>";
    }

    @RequestMapping("/D4")
    public Object HTML1(){
        return "/aa.js";
    }

    @RequestMapping("/D5")
    public Object HTML2(){
        return "/bb.css";
    }

//    4.返回JSON
    @RequestMapping("/D6")
    @ResponseBody
    public HashMap<String,String> returnJson(){
        HashMap<String,String> map=new HashMap<>();
        map.put("java","java value");
        map.put("MySQL","MySQL Value");
        map.put("Vue","Vue.js");
        return map;
    }
//    5.设置状态码
    @RequestMapping("/D7")
    public String setStatus(HttpServletResponse response){
        response.setStatus(404);
        return "状态码设置成功~";
    }

//    6.设置Content-Type
        @RequestMapping(value = "/D8",produces = "application/json;charset=utf-8" )
    public String setCT(){
        return "{\"success\":true}";
    }
    //7.设置其他Header
    @RequestMapping("/D9")
    public String setHeader(HttpServletResponse response){
        response.setHeader("MyHeadrer","MyHeaderValue");
        return "设置HeaderSuccess";
    }
}
